package com.shqcjd.preinstallmobile.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.preinstallmobile.R;
import com.shqcjd.preinstallmobile.model.pojo.ProcessBackBean;

import java.util.List;

public class ProcessBackAdapter extends BaseQuickAdapter<ProcessBackBean.ItemsBean,BaseViewHolder> {
    private Context context;
    public ProcessBackAdapter(@Nullable List<ProcessBackBean.ItemsBean> data, Context context) {
        super(R.layout.item_process_back, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, ProcessBackBean.ItemsBean item) {
        helper.setText(R.id.tv_item_equipment_list_name, item.patrol_route_name);
        helper.setText(R.id.tv_item_equipment_list_type, item.user_name);
        helper.setText(R.id.tv_item_equipment_list_code, (helper.getAdapterPosition()+1)+"");
        if(item.begin_time.equals("")){
            helper.getView(R.id.tv_item_equipment_defect_start).setVisibility(View.GONE);
        }else{
            helper.getView(R.id.tv_item_equipment_defect_start).setVisibility(View.VISIBLE);
            helper.setText(R.id.tv_item_equipment_defect_start, "开始时间: "+item.begin_time);
        }

        if(item.end_time.equals("")){
            helper.getView(R.id.tv_item_equipment_defect_end).setVisibility(View.GONE);
        }else{
            helper.getView(R.id.tv_item_equipment_defect_end).setVisibility(View.VISIBLE);
            helper.setText(R.id.tv_item_equipment_defect_end, "结束时间: "+item.end_time);
        }

        TextView tv_item_equipment_list_kks = helper.getView(R.id.tv_item_equipment_list_kks);
        if(item.status==1){
            tv_item_equipment_list_kks.setText("● 巡检中");
            tv_item_equipment_list_kks.setTextColor(Color.parseColor("#F25858"));
        }else if(item.status==2){
            tv_item_equipment_list_kks.setText("● 巡检结束");
            tv_item_equipment_list_kks.setTextColor(Color.parseColor("#598ae9"));
        }

        ImageView iv_item_equipment_list_pic = helper.getView(R.id.iv_item_equipment_list_pic);
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.ic_default_small)	//加载成功之前占位图
                .error(R.mipmap.ic_default_small);//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都
        Glide.with(context)
                .load(item.img)
                .apply(options)
                .into(iv_item_equipment_list_pic);

    }

}
